#include <iostream>
using namespace std;

int* return_local_adress(int x){
	
	/*
 	*Bu fonksyon UB olarak tanimlaniyor yani :
	Undefined behavior results when programs attempt to do things for which the standard defines no semantics, and requires no diagnostic either. 
	Examples include dereferencing invalid pointers and dividing by zero. Executing such programs may cause them to produce incorrect results, 
	crash, silently "work", or even format the hard drive.i
	*/
	
	int a;
	a= x*2*10;

	// cok ilginc bisi bu alttakini kaldirinca adam gibi calisiyo
	// ama o olmayinca ekrana 0 basiyor	
	//cout << "The value in the func is : " << a <<endl;
	
	return &a;
}

int* correct_return_local_adress(int x){

	//That one is kepit on the heap so it is not a
	//problem in that case

	int* a=new int();
	
	*a = x*2*10;
	//cout << "The value in the func is : " << *a <<endl;

	return a;
}


int main1(int argc,char **argv){

	int temp = 10;
	int *temp_ptr;
	
	temp_ptr = return_local_adress(temp);
	cout << "The pitfall from local adress :" << *temp_ptr << endl;
	
	temp_ptr = correct_return_local_adress(temp);
	cout << "The correct pitfall from local adress :" << *temp_ptr << endl;
	

	return 0;
}
